<template>
  <div class="app-container">
    <!-- 查询模块 -->
    <div class="formDiv">
      <el-form ref="form" :inline="true" :model="form" label-width="130px!important">
        <el-row>
          <el-col :span="6">
            <el-form-item label="补贴单号">
              <el-input v-model="form.applySn" />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="流水单号">
              <el-input v-model="form.orderSn" />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="姓名/手机号">
              <el-input v-model="form.userInfo" />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="审核状态">
              <el-select v-model="form.applyStatus" placeholder="请选择">
                <el-option
                  v-for="item in applyOption"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="补贴类型">
              <el-select v-model="form.allowanceType" placeholder="请选择">
                <el-option
                  v-for="item in allowOption"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="报单时间">
              <el-date-picker
                v-model="createdAt"
                value-format="yyyy-MM-dd HH:mm:ss"
                type="daterange"
                range-separator="-"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                :default-time="['00:00:00', '23:59:59']"
              />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="初审时间">
              <el-date-picker
                v-model="firstTime"
                value-format="yyyy-MM-dd HH:mm:ss"
                type="daterange"
                range-separator="-"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                :default-time="['00:00:00', '23:59:59']"
              />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="复审时间">
              <el-date-picker
                v-model="applyTime"
                value-format="yyyy-MM-dd HH:mm:ss"
                type="daterange"
                range-separator="-"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                :default-time="['00:00:00', '23:59:59']"
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="报单类型">
              <el-select v-model="form.formType" placeholder="请选择">
                <el-option label="全部" :value="null"></el-option>
                <el-option label="美美咖报单" :value="0"></el-option>
                <el-option label="传统报单" :value="1"></el-option>
              </el-select>
            </el-form-item>
          </el-col>

          <el-col :span="8">
            <el-form-item label="活动名称">
              <el-select v-model="form.salesType" placeholder="请选择">
                <el-option label="全部" :value="null" />
                <el-option :label="item" :value="index" v-for="(item,index) in plist" :key="index" />
                <!-- <el-option label="无促销活动" :value="0" />
                <el-option label="2020服务商加盟全额补" :value="1" />
                <el-option label="超级卖手90%补贴" :value="2" />
                <el-option label="2020定金全额补" :value="2020" />-->
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="团队电话">
              <el-input v-model="form.teamUserPhone"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="上级姓名">
              <el-input v-model="form.serverName"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="上级电话">
              <el-input v-model="form.serverPhone"></el-input>
            </el-form-item>
          </el-col>

          <el-col :span="6">
            <el-button style="margin-left:60px" type="primary" @click="searchFn">查询</el-button>
            <el-button
              style="margin-left:60px"
              type="primary"
              v-if="hasPermission('AdminAllowanceProvider.allowanceListExcel')"
              @click="exprofun"
            >导出</el-button>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <!-- 主页列表 -->
    <div v-loading="tableLoading" class="listDiv">
      <!-- table列表 -->
      <el-table :data="tableData" style="width: 100%">
        <el-table-column label="单号">
          <template slot-scope="scope">
            <div>补贴单号：{{ scope.row.applySn }}</div>
            <div>流水单号：{{ scope.row.orderSn }}</div>
          </template>
        </el-table-column>
        <el-table-column prop="userInfo" label="用户信息">
          <template slot-scope="scope">{{ scope.row.userInfo |phonereg }}</template>
        </el-table-column>
        <el-table-column prop="birthdate" label="用户生日" />
        <el-table-column prop="salesTypeValue" label="活动名称" />
        <el-table-column label="推荐人">
          <template slot-scope="scope">
            <div>补贴单：{{ scope.row.applyServerInfo |phonereg }}</div>
            <div>流水单：{{ scope.row.orderServerInfo |phonereg }}</div>
          </template>
        </el-table-column>
        <el-table-column prop="formType" label="报单类型"></el-table-column>
        <el-table-column prop="projectName" label="医院项目">
          <template slot-scope="scope">
            <div>{{ scope.row.hospitalName }}</div>
            <div>{{ scope.row.projectName }}</div>
          </template>
        </el-table-column>
        <el-table-column label="金额">
          <template slot-scope="scope">
            消费金额：{{ scope.row.totalMoney }}
            <br />
            奖励金额：{{ (scope.row.applyMoney-0)+ (scope.row.useCoin-0)}}
            <br />
            实际补贴金额：{{ scope.row.applyMoney }}
            <br />
            金币：{{ scope.row.useCoin }}
          </template>
        </el-table-column>
        <el-table-column prop="isAllowance" label="补贴">
          <template slot-scope="scope">
            <span v-if="scope.row.isAllowance">是</span>
            <span v-else>否</span>
            <span></span>
          </template>
        </el-table-column>
        <el-table-column prop="teamUserName" label="团队" />
        <el-table-column prop="applyStatus" label="状态">
          <template slot-scope="scope">
            <div>审核状态：{{ scope.row.applyStatus }}</div>
            <div>合同：{{ scope.row.contractType }}</div>
            <div>保险：{{ scope.row.isBx }}</div>
            <div>金融：{{ scope.row.jrStatusValue }}</div>
          </template>
        </el-table-column>
        <!-- <el-table-column prop="isBx" label="是否购买保险" /> -->
        <el-table-column prop="butlerName" label="管家">
          <template slot-scope="scope">
            {{ scope.row.butlerName }}
            <br />
            {{ scope.row.butlerPhone |phonereg}}
          </template>
        </el-table-column>
        <!-- <el-table-column prop="createdAt" label="创建时间" /> -->
        <el-table-column prop="identity" label="创建时间">
          <template slot-scope="scope">
            <div>创建时间:{{ scope.row.createdAt }}</div>
            <div>签约协议:{{ scope.row.userSignDate }}</div>
            <div>首次补贴:{{ scope.row.allowanceTime }}</div>
          </template>
        </el-table-column>
        <el-table-column label="审核时间">
          <template slot-scope="scope">
            <div>初审时间：{{ scope.row.firstTime }}</div>
            <div v-if="scope.row.applyStatus == '复审通过'">复审时间：{{ scope.row.applyTime }}</div>
            <div>初审人:{{ scope.row.firstUsername }}</div>
            <div>复审人:{{ scope.row.applyUsername }}</div>
          </template>
        </el-table-column>
        <el-table-column fixed="right" label="操作" width="200">
          <template slot-scope="scope">
            <!-- 初审通过 -->
            <div v-if="scope.row.applyStatus == '初审通过'">
              <el-button
                v-if="hasPermission('AdminAllowanceProvider.doTwoAudit')"
                type="text"
                size="small"
                @click="toRoutes('subsidyManageRecheck', scope.row.id)"
              >复审</el-button>

              <el-button
                v-if="hasPermission('AdminAllowanceProvider.doEditInfo')"
                type="text"
                size="small"
                @click="toRoutes('subsidyManageEdit', scope.row.id)"
              >编辑</el-button>

              <el-button
                v-if="hasPermission('AdminAllowanceProvider.detailProject')"
                type="text"
                size="small"
                @click="
                  toRoutes('subsidyManageInfo', scope.row.id, 'detailProject')
                "
              >详情</el-button>
              <el-button
                v-if="hasPermission('AdminAllowanceProvider.getRewardList')"
                type="text"
                size="small"
                @click="toRoutes('subsidyManageInstallment', scope.row.id)"
              >分期</el-button>
              <span
                v-if="
                  hasPermission('AdminAllowanceRefundProvider.editStopStart')
                "
              >
                <el-button
                  v-if="scope.row.status == 0"
                  type="text"
                  size="small"
                  @click="
                    stopDialogFn(
                      scope.row.reason,
                      scope.row.id,
                      scope.row.status
                    )
                  "
                >恢复</el-button>
              </span>

              <span
                v-if="
                  hasPermission('AdminAllowanceRefundProvider.editStopStart')
                "
              >
                <el-button
                  v-if="scope.row.status == 1"
                  type="text"
                  size="small"
                  @click="
                    stopDialogFn(
                      scope.row.reason,
                      scope.row.id,
                      scope.row.status
                    )
                  "
                >暂停</el-button>
              </span>

              <el-button
                v-if="scope.row.agreementUrl"
                type="text"
                size="small"
                @click="jump(scope.row.agreementUrl)"
              >协议</el-button>

              <span v-if="hasPermission('AdminAllowanceProvider.contractType')">
                <el-button
                  v-if="scope.row.contractType == '0'"
                  type="text"
                  size="small"
                  @click="receivedContract(scope.row.id)"
                >收到合同</el-button>
              </span>
            </div>
            <div class="divInline">
              <div
                v-if="
                  scope.row.applyStatus == '初审通过' ||
                    scope.row.applyStatus == '复审通过' ||
                    scope.row.applyStatus == '复审驳回'
                "
              >
                <el-button
                  v-if="
                    scope.row.jrStatus == 0 &&
                      hasPermission(
                        'AdminAllowanceProvider.changeFinanceAccountNumberStatus'
                      )
                  "
                  type="text"
                  size="small"
                  @click="finance(scope.row)"
                >金融账号</el-button>
                <el-button
                  v-if="
                    scope.row.jrStatus == 1 &&
                      hasPermission(
                        'AdminAllowanceProvider.changeFinanceAccountNumberStatus'
                      )
                  "
                  type="text"
                  size="small"
                  @click="finance(scope.row)"
                >关闭金融</el-button>
              </div>
              <!-- 按钮显影 -->
              <!-- 未签名 -->
              <div v-if="scope.row.applyStatus == '未签名'">
                <el-button
                  v-if="hasPermission('AdminAllowanceProvider.getReject')"
                  type="text"
                  size="small"
                  @click="rejected(scope.row.id)"
                >驳回</el-button>
                <el-button
                  v-if="hasPermission('AdminAllowanceProvider.detailProject')"
                  type="text"
                  size="small"
                  @click="
                    toRoutes('subsidyManageInfo', scope.row.id, 'detailProject')
                  "
                >详情</el-button>
              </div>
              <!-- 未审核 -->
              <div
                v-if="
                  scope.row.applyStatus == '未审核' &&
                    scope.row.formType.indexOf('传统') == -1
                "
              >
                <el-button
                  type="text"
                  size="small"
                  v-if="hasPermission('AdminAllowanceProvider.dealAudit')"
                  @click="toRoutes('subsidyManageTrial', scope.row.id)"
                >初审</el-button>
                <span v-if="scope.row.formType">
                  <el-button
                    v-if="
                      hasPermission('AdminAllowanceProvider.getReject') &&
                        scope.row.formType.indexOf('传统') == -1
                    "
                    type="text"
                    size="small"
                    @click="rejected(scope.row.id)"
                  >驳回</el-button>
                </span>

                <el-button
                  v-if="hasPermission('AdminAllowanceProvider.doEditInfo')"
                  type="text"
                  size="small"
                  @click="toRoutes('subsidyManageEdit', scope.row.id)"
                >编辑</el-button>

                <!-- <el-button
                  v-if="hasPermission('AdminAllowanceProvider.detailProject')"
                  type="text"
                  size="small"
                  @click="toRoutes('subsidyManageInfo',scope.row.id,'detailProject')"
                >详情</el-button>-->
                <span v-if="scope.row.formType">
                  <span
                    v-if="
                      hasPermission(
                        'AdminAllowanceRefundProvider.editStopStart'
                      ) && scope.row.formType.indexOf('传统') == -1
                    "
                  >
                    <el-button
                      v-if="scope.row.status == 0"
                      type="text"
                      size="small"
                      @click="
                        stopDialogFn(
                          scope.row.reason,
                          scope.row.id,
                          scope.row.status
                        )
                      "
                    >恢复</el-button>
                  </span>
                </span>
                <span v-if="scope.row.formType">
                  <span
                    v-if="
                      hasPermission(
                        'AdminAllowanceRefundProvider.editStopStart'
                      ) && scope.row.formType.indexOf('传统') == -1
                    "
                  >
                    <el-button
                      v-if="scope.row.status == 1"
                      type="text"
                      size="small"
                      @click="
                        stopDialogFn(
                          scope.row.reason,
                          scope.row.id,
                          scope.row.status
                        )
                      "
                    >暂停</el-button>
                  </span>
                </span>
              </div>
              <div
                v-if="
                  scope.row.applyStatus == '未审核' &&
                    scope.row.formType.indexOf('传统') > -1
                "
              >
                <el-button
                  v-if="hasPermission('AdminAllowanceProvider.doTwoAudit')"
                  type="text"
                  size="small"
                  @click="toRoutes('subsidyManageRecheck', scope.row.id)"
                >复审</el-button>
                <el-button
                  type="text"
                  size="small"
                  v-if="hasPermission('AdminAllowanceProvider.getReject')"
                  @click="rejected(scope.row.id)"
                >驳回</el-button>
                <el-button
                  v-if="hasPermission('AdminAllowanceProvider.doEditInfo')"
                  type="text"
                  size="small"
                  @click="toRoutes('subsidyManageEdit', scope.row.id)"
                >编辑</el-button>
              </div>
              <!-- 复审通过 -->
              <div v-if="scope.row.applyStatus == '复审通过'">
                <el-button
                  v-if="hasPermission('AdminAllowanceProvider.setRefund')"
                  type="text"
                  size="small"
                  @click="toRoutes('subsidyManageRefund', scope.row.id)"
                >退款</el-button>

                <el-button
                  v-if="hasPermission('AdminAllowanceProvider.doEditInfo')"
                  type="text"
                  size="small"
                  @click="toRoutes('subsidyManageEdit', scope.row.id)"
                >编辑</el-button>

                <!-- 状态为初审通过时显示分期 -->
                <div v-if="scope.row.formType.indexOf('传统') == -1">
                  <el-button
                    v-if="hasPermission('AdminAllowanceProvider.getRewardList')"
                    type="text"
                    size="small"
                    @click="toRoutes('subsidyManageInstallment', scope.row.id)"
                  >分期</el-button>

                  <el-button
                    v-if="hasPermission('AdminAllowanceProvider.detailProject')"
                    type="text"
                    size="small"
                    @click="
                      toRoutes(
                        'subsidyManageInfo',
                        scope.row.id,
                        'detailProject'
                      )
                    "
                  >详情</el-button>

                  <span
                    v-if="
                      hasPermission(
                        'AdminAllowanceRefundProvider.editStopStart'
                      )
                    "
                  >
                    <el-button
                      v-if="scope.row.status == 0"
                      type="text"
                      size="small"
                      @click="
                        stopDialogFn(
                          scope.row.reason,
                          scope.row.id,
                          scope.row.status
                        )
                      "
                    >恢复</el-button>
                  </span>

                  <span
                    v-if="
                      hasPermission(
                        'AdminAllowanceRefundProvider.editStopStart'
                      )
                    "
                  >
                    <el-button
                      v-if="scope.row.status == 1"
                      type="text"
                      size="small"
                      @click="
                        stopDialogFn(
                          scope.row.reason,
                          scope.row.id,
                          scope.row.status
                        )
                      "
                    >暂停</el-button>
                  </span>

                  <el-button
                    v-if="scope.row.agreementUrl"
                    type="text"
                    size="small"
                    @click="jump(scope.row.agreementUrl)"
                  >协议</el-button>

                  <span v-if="hasPermission('AdminAllowanceProvider.contractType')">
                    <el-button
                      v-if="scope.row.contractType == '0'"
                      type="text"
                      size="small"
                      @click="receivedContract(scope.row.id)"
                    >收到合同</el-button>
                  </span>
                  <span
                    v-if="
                      hasPermission(
                        'AdminUserRewardTransProvider.updateUserRewardTrans'
                      )
                    "
                  >
                    <el-button
                      v-if="scope.row.refundType == '0' && hasPermission('AdminUserRewardTransProvider.updateUserRewardTrans')"
                      type="text"
                      size="small"
                      @click="
                        toRoutesComm(
                          'rewardEdit',
                          scope.row.id,
                          scope.row.orderId,
                          scope.row.allowanceMoney
                        )
                      "
                    >奖励修改</el-button>
                  </span>
                </div>
              </div>
              <!-- 复审通过结束 -->

              <!-- 复审驳回 -->
              <div v-if="scope.row.applyStatus.indexOf('驳回') > -1">
                <el-button
                  v-if="hasPermission('AdminAllowanceProvider.doEditInfo')"
                  type="text"
                  size="small"
                  @click="toRoutes('subsidyManageEdit', scope.row.id)"
                >编辑</el-button>
                <el-button
                  v-if="hasPermission('AdminAllowanceProvider.detailProject')"
                  type="text"
                  size="small"
                  @click="
                    toRoutes('subsidyManageInfo', scope.row.id, 'detailProject')
                  "
                >详情</el-button>
              </div>
            </div>
          </template>
        </el-table-column>
      </el-table>
      <!-- 暂停弹出窗 -->
      <el-dialog
        :title="elTxt"
        :visible.sync="stopDialog"
        width="480px"
        :before-close="handleClose"
      >
        <el-form :inline="true" label-width="100px">
          <el-row>
            <el-col :span="24">
              <el-form-item label="上次操作原因">
                <span class="spanToInput">{{ stopList.note | filterNull }}</span>
                <!-- {{statusFlag}} -->
                <!-- <span v-if="statusFlag==1">暂停</span>
                <span v-else>恢复</span>-->
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="操作人">
                <span class="spanToInput">{{ stopList.name | filterNull }}</span>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item :label="elLabel">
                <el-input v-model="stopForm.note" />
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
        <span slot="footer" class="dialog-footer">
          <el-button @click="stopDialog = false">取 消</el-button>
          <el-button type="primary" @click="stopSubmitFn()">确 定</el-button>
        </span>
      </el-dialog>
      <!-- 驳回弹出窗 -->
      <el-dialog title="驳回" :visible.sync="dialogs" width="480px" :before-close="handleCloses">
        <el-form :inline="true" label-width="100px">
          <el-row>
            <el-col :span="24">
              <el-form-item label="驳回理由">
                <el-input v-model="rejectForm.remark" />
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
        <span slot="footer" class="dialog-footer">
          <el-button @click="dialogs = false">取 消</el-button>
          <el-button type="primary" @click="rejectedFn()">确 定</el-button>
        </span>
      </el-dialog>
      <!-- 分页 -->
      <div class="pagesCon">
        <div>
          <el-pagination
            :current-page="listForm.pageNum"
            :page-sizes="page_sizes"
            :page-size="listForm.limit"
            layout="total, sizes, prev, pager, next, jumper"
            :total="page_totals"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
          />
        </div>
      </div>
    </div>

    <el-dialog title="提示" :visible.sync="dialogVisible" width="20%">
      <el-form :inline="true" label-width="80px" label-position="right">
        <el-form-item label="金融账号">
          <!-- {{dialogVisible}} -->
          <el-select
            v-if="dialogVisible"
            v-model="adddatas.accountNumber"
            filterable
            placeholder="请选择金融账户"
          >
            <el-option
              v-for="item in options"
              :key="item.username"
              :label="item.username + ':' + item.accountName"
              :value="item.username"
            />
          </el-select>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="sure()">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
// allowanceListDelete
import {
  allowanceList,
  contractType,
  editStopStart,
  getReject,
  getFinanceAccountUserList,
  changeFinanceAccountNumberStatus
} from "@/api/subsidyManage";
import commonFn from "@/utils/common.js";
import { exportfile, exportfun } from "@/api/commjs/exprot";
export default {
  name: "SubsidyManageIndex",
  filters: {
    cardType: function(e) {
      return window.helper.cardType(String(e));
    },
    filterNull(e) {
      if (!e) {
        return "暂无";
      } else {
        return e;
      }
    }
  },
  data() {
    return {
      options: [],
      adddatas: { accountNumber: "" }, // 金融添加
      dialogVisible: false,
      elTxt: "",
      elLabel: "",
      val: "1",
      stopDialog: false,
      dialogs: false,
      dates: "",
      applyOption: [],
      allowOption: [],
      createdAt: null,
      firstTime: null,
      applyTime: null,
      tableLoading: true,
      stopList: {},
      stopForm: {
        id: null,
        status: null,
        note: ""
      },
      form: {
        // salesType: 0,
        ispc: 1,
        applySn: null,
        orderSn: null,
        userInfo: null,
        applyStatus: null,
        allowanceType: null,
        createdAtBegin: null,
        createdAtEnd: null,
        firstTimeBegin: null,
        firstTimeEnd: null,
        applyTimeBegin: null,
        applyTimeEnd: null,
        pageNum: 1,
        pageSize: 10
      },
      tableData: [],
      page_sizes: [10, 30, 50, 100],
      page_totals: 60,
      plist: {},
      listForm: {
        orderSn: "",
        pageNum: 1,
        pageSize: 10
      },
      rejectForm: {
        id: null,
        remark: null
      },
      statusFlag: null
    };
  },
  watch: {
    statusFlag(val) {
      if (val == 1) {
        this.elTxt = "暂停";
        this.elLabel = "暂停理由";
      } else {
        this.elTxt = "恢复";
        this.elLabel = "恢复理由";
      }
    }
  },
  inject: ["reload"],
  mounted() {
    this.plist = commonFn.list;
    this.listForm.orderSn = this.$route.query.userId;
    this.form.orderSn = this.listForm.orderSn;
    this.getList(this.listForm);
    this.getOption();
    this.getFinanceAccountUserList();
  },
  methods: {
    async exprofun() {
      let dates = { ...this.form };
      dates.createdBy = this.$store.state.user.name;
      let res = await exportfun(
        "com.mmk.report.api.AdminReportProvider/1.0.0/exportAllowance.html",
        dates,
        "",
        1
      );
      this.$message({
        message: res.data.msg,
        type: "warning"
      });
    },
    sure() {
      console.log(this.adddatas);
      changeFinanceAccountNumberStatus(this.adddatas).then(res => {
        console.log(res);
        this.$message({
          message: res.data.msg,
          type: "warning"
        });
        if (res.data.code == 0) {
          this.dialogVisible = false;
        }
        this.getList(this.form);
      });
    },
    // getFinanceAccountUserList
    getFinanceAccountUserList() {
      getFinanceAccountUserList().then(res => {
        console.log(res);
        if (res.data.code == 0) {
          this.options = res.data.data;
        }
      });
    },
    // 金融账号开启或关闭
    finance(data) {
      const ispoen = false;
      this.adddatas.id = data.id;
      this.adddatas.status = data.jrStatus == 1 ? 0 : 1;
      this.adddatas.accountNumber = "";
      if (data.jrStatus == 0) {
        this.dialogVisible = true;
      } else {
        // 关闭
        this.$alert("确定关闭吗", "提示", {
          confirmButtonText: "确定",
          callback: action => {
            if (action == "confirm") {
              this.sure();
            }
            // this.$message({
            //   type: "warning",
            //   message: `action: ${action}`
            // });
          }
        });
      }
    },
    // 按钮权限
    hasPermission(e) {
      return window.helper.hasPermission(e);
    },
    // 驳回
    rejected(e) {
      this.rejectForm.id = Number(e);
      this.dialogs = true;
    },
    // 驳回动作
    rejectedFn(e) {
      // console.log(this.rejectForm)
      const datas = this.rejectForm;
      getReject(datas)
        .then(res => {
          this.dialogs = false;
          if (!res.data.code) {
            this.succStatus("驳回");
            this.reload();
          } else {
            this.$message.error(res.data.msg);
          }
        })
        .catch(error => {
          this.dialogs = false;
          this.$message.error(error);
        });
    },
    // 协议跳转
    jump(e) {
      window.open(e);
    },
    // 获取对应options
    getOption() {
      this.applyOption = window.helper.applyStatus("listReturn");
      this.allowOption = window.helper.allowanceType("listReturn");
    },
    // 成功状态弹窗
    succStatus(txt) {
      this.$message({
        message: txt + "成功",
        type: "success"
      });
    },
    // 失败状态弹窗
    errorStatus(txt) {
      this.$message.error(txt + "失败");
    },
    // 暂停/恢復
    stopDialogFn(e, id, status) {
      console.log(status);
      this.stopList = e;
      this.stopForm["id"] = Number(id);
      if (status == 0) {
        this.statusFlag = 0;
        this.stopDialog = true;
        // this.stopForm["status"] = 1;
        // this.$confirm("是否恢复补贴单正常?", "提示", {
        //   confirmButtonText: "确定",
        //   cancelButtonText: "取消",
        //   type: "warning"
        // })
        // .then(() => {
        //  this.stopSubmitFn(status);
        // })
        // .catch(() => {});
      } else {
        this.statusFlag = 1;
        this.stopDialog = true;
      }
    },
    // 暂停提交
    stopSubmitFn() {
      let datas = null;
      datas = this.stopForm;
      if (this.statusFlag == 1) {
        datas["status"] = 0;
      } else {
        datas["status"] = 1;
      }
      editStopStart(datas)
        .then(res => {
          this.stopDialog = false;
          if (!res.data.code) {
            if (this.statusFlag == 0) {
              this.statusFlag = 0;
              this.succStatus("恢复");
            } else {
              this.statusFlag = 1;
              this.succStatus("暂停");
            }
            this.reload();
          } else {
            this.$message.error(res.data.msg);
          }
        })
        .catch(error => {
          if (this.statusFlag == 0) {
            this.stopDialog = false;
          }
          this.$message.error(error);
        });
    },
    // 查询
    searchFn() {
      this.form.pageNum = 1;
      if (this.createdAt != null) {
        if (this.createdAt.length) {
          this.form.createdAtBegin = this.createdAt[0];
          this.form.createdAtEnd = this.createdAt[1];
        }
      } else {
        this.form.createdAtBegin = "";
        this.form.createdAtEnd = "";
      }
      if (this.firstTime != null) {
        if (this.firstTime.length) {
          this.form.firstTimeBegin = this.firstTime[0];
          this.form.firstTimeEnd = this.firstTime[1];
        }
      } else {
        this.form.firstTimeBegin = "";
        this.form.firstTimeEnd = "";
      }
      if (this.applyTime != null) {
        if (this.applyTime.length) {
          this.form.applyTimeBegin = this.applyTime[0];
          this.form.applyTimeEnd = this.applyTime[1];
        }
      } else {
        this.form.applyTimeBegin = "";
        this.form.applyTimeEnd = "";
      }
      this.getList(this.form);
      // console.log(JSON.stringify(this.form))
      // console.log(this.form)
    },
    handleClose() {
      this.stopDialog = false;
    },
    handleCloses() {
      this.dialogs = false;
    },
    // 列表数据获取
    getList(e) {
      this.tableLoading = true;
      const datas = e;
      allowanceList(datas)
        .then(res => {
          if (!res.data.code) {
            // console.log(res)
            this.tableData = res.data.data.list;
            this.page_totals = res.data.data.count;
          } else {
            this.$message.error(res.data.msg);
          }
          this.tableLoading = false;
        })
        .catch(error => {
          this.$message.error(error);
        });
    },
    //重新修改
    toRoutesComm(e, id, ids, amount) {
      const route = {
        name: e,
        query: {
          id: id,
          ids: ids,
          amount: amount
        }
      };
      //  this.$router.push(route);
      let routeUrl = this.$router.resolve(route);
      window.open(routeUrl.href, "_blank");
    },
    // 路由跳转
    toRoutes(e, id, ids, amount) {
      const route = {
        name: e,
        query: {
          id: id,
          ids: ids,
          amount: amount
        }
      };
      //  this.$router.push(route);
      let routeUrl = this.$router.resolve(route);
      window.open(routeUrl.href, "_blank");
    },
    // 改变页面条数
    handleSizeChange(val) {
      this.form.pageSize = val;
      this.getList(this.form);
    },
    // 选择页数
    handleCurrentChange(val) {
      this.form.pageNum = val;
      this.getList(this.form);
    },
    // 收到合同
    receivedContract(e) {
      const datas = { id: Number(e) };
      this.$confirm("是否确认收到了合同？", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          contractType(datas).then(res => {
            if (!res.data.code) {
              this.$message({
                message: "成功收到合同",
                type: "success"
              });
              this.getList(this.form);
              this.reload();
            } else {
              this.$message.error(res.data.msg);
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消"
          });
        });
    },
    // 删除
    deleteList(e) {
      const datas = { id: e };
      // console.log(datas)
      this.$confirm("删除该条数据, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          // console.log(datas)

          allowanceListDelete(datas).then(res => {
            if (!res.data.code) {
              this.succStatus("删除");
              this.getList(this.form);
            } else {
              this.$message.error(res.data.msg);
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除"
          });
        });
    }
  }
};
</script>
<style scoped>
/* 分页 */
.pagesCon {
  height: 40px;
  margin-top: 20px;
}
.pagesCon > div {
  float: right;
}
.divInline > div {
  display: inline;
}
.formDiv /deep/ .el-form-item__label {
  width: auto !important;
}
/* 表单样式修改 */
.el-range-editor--medium.el-input__inner {
  width: 236px;
}
</style>
